#pragma once
#include "mut.h"
#include <map>
#include <algorithm>

class CMUTTexManager;
class CMUTTexture{
public:
	int Ref;
	LPDIRECT3DTEXTURE9 pTex;

	CMUTTexManager* manager;
	TString name;

	CMUTTexture(): Ref(0), pTex(0), manager(0) {}
	HRESULT CreateFromFile( LPWSTR fn );
	HRESULT Create( int Width, int Height, DWORD Usage, D3DFORMAT Fmt, D3DPOOL Pool );
	void Release( HANDLE hEvent = 0 );
	operator LPDIRECT3DBASETEXTURE9(){
		return pTex;
	}
	operator LPDIRECT3DTEXTURE9(){
		return pTex;
	}
};

class CMUTTexManager{
public:
	map< TString, CMUTTexture* > mtex;
	CMUTTexture* GetTexture( LPWSTR fn, HANDLE hEvent = 0 );
	void ReleaseTexture( CMUTTexture* pTex, HANDLE hEvent = 0 );
	void ReleaseAll();
};

template <class T>
class CMUTSimpleManager{
public:
	map< TString, T* > mres;
	T* Get( LPWSTR fn );
	void Release();
};